package com.wash.shoes.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.SecurityUtils;
import com.wash.shoes.entity.WorkOrderPo;
import com.wash.shoes.mapper.UserShopMapper;
import com.wash.shoes.mapper.WorkOrderMapper;
import com.wash.shoes.service.IWorkOrderService;
import com.wash.shoes.util.HeaderUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * 工单服务类
 */
@Service
@RequiredArgsConstructor
public class WorkOrderServiceImpl extends ServiceImpl<WorkOrderMapper, WorkOrderPo> implements IWorkOrderService {

    private final UserShopMapper userShopMapper;

    /**
     * 工单列表
     *
     * @param page
     * @param orderNo
     * @param phone   手机号
     * @param <E>
     * @return
     */
    @Override
    public IPage<WorkOrderPo> page(IPage<?> page, String orderNo, String phone) {
        // 用户账号绑定的类型
        Long userId = SecurityUtils.getUserId();
        // 获取用户绑定的类型,
        List<String> userBindTypeList = userShopMapper.getUserBindType(userId + "");
        String userBindType = null;
        if (!CollectionUtils.isEmpty(userBindTypeList)) {
            userBindType = userBindTypeList.get(0);
        }
        String shopIdStr = HeaderUtil.getShopIdStr();

        return getBaseMapper().pageList(page, shopIdStr, userBindType, orderNo, phone);
    }
}